﻿using Gp.Scripts.Core;
using Gp.Scripts.GUI;
using PixelCrushers.DialogueSystem;
using QFramework;
using UnityEngine;
using UnityEngine.EventSystems;

namespace GP.Scripts.GUI {
    public class NextClickPlace : MonoBehaviour,IPointerClickHandler,IController {
        public StandardDialogueUI dialogueUI;

        [Tooltip("Typewriter effect to fast forward if it's not done playing.")]
        public AbstractTypewriterEffect typewriterEffect;


        private bool _isUsable = true;
        public void Start()
        {
            if (typewriterEffect == null)
            {
                typewriterEffect = GetComponentInChildren<UnityUITypewriterEffect>();
            }

            // this.RegisterEvent<DialogueSkipEvent>((e) => {
            //     this._isUsable = e.status;
            // });
        }
        

        public void OnPointerClick(PointerEventData eventData) {
            if (!_isUsable) {
                return;
            }
            if ((typewriterEffect != null) && typewriterEffect.isPlaying)
            {
                typewriterEffect.Stop();
            }
            else {
                if (dialogueUI != null) {
                    dialogueUI.OnContinueConversation();
                }
            }
        }

        public IArchitecture GetArchitecture() {
            return MainArchitecture.Interface;
        }
    }
}